package com.jjz.id.common;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.Version;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.time.Instant;
import java.util.Objects;

/**
 * @author ZJL
 * @create 2025-05-27-16:11
 */
@Setter
@Getter
public class BaseEntity implements Serializable {
    @Version
    @TableField(
            value = "data_version",
            fill = FieldFill.INSERT
    )
    protected Integer version;
    @TableField(
            value = "create_time",
            fill = FieldFill.INSERT,
            updateStrategy = FieldStrategy.NEVER
    )
    @JsonFormat(
            pattern = "yyyy-MM-dd HH:mm:ss",
            timezone = "GMT+8"
    )
    protected Instant createTime;
    @TableField(
            value = "create_user",
            fill = FieldFill.INSERT,
            updateStrategy = FieldStrategy.NEVER
    )
    protected String createUser;
    @TableField(
            value = "update_user",
            fill = FieldFill.UPDATE,
            insertStrategy = FieldStrategy.NEVER
    )
    protected String updateUser;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        BaseEntity that = (BaseEntity) o;
        return Objects.equals(version, that.version) && Objects.equals(createTime, that.createTime) && Objects.equals(createUser, that.createUser) && Objects.equals(updateUser, that.updateUser) && Objects.equals(updateTime, that.updateTime);
    }

    @Override
    public int hashCode() {
        return Objects.hash(version, createTime, createUser, updateUser, updateTime);
    }
    protected boolean canEqual(final Object other) {
        return other instanceof BaseEntity;
    }

    @TableField(
            value = "update_time",
            fill = FieldFill.UPDATE,
            insertStrategy = FieldStrategy.NEVER
    )
    @JsonFormat(
            pattern = "yyyy-MM-dd HH:mm:ss",
            timezone = "GMT+8"
    )
    protected Instant updateTime;
}
